/*
 * Copyright (c) 2010-2013 Ruben Chakhmakhchyan. All rights reserved.
 * 
 * This file contains Original Code and/or Modifications of Original Code
 * as defined in and that are subject to the Eclipse Public License
 * Version 1.0 (the 'License'). You may not use this file except in
 * compliance with the License. Please obtain a copy of the License at
 * http://opensource.org/licenses/EPL-1.0 and read it before using this file.
 */

#pragma once

#include "commontypes.h"
#include "list.h"
#include "plugin_model.h"


class ImageList
{
private:

    struct Item
    {
        byte_t* data;
        size_t size;
        //DocumentFormat format;
        bool isDirect; // Identified wether the item data is a pointer to the stored image

        void dispose()
        {
            if ( !isDirect )
                delete data;
        }
    };

public:

    ImageList() { }

    ~ImageList()
    {
        for ( auto& i : m_items )
        {
            i.dispose();
        }
    }

    bool getItem( uint_t index, byte_t*& data, size_t& size )
    {
        Item& item = m_items[ index ];
        data = item.data;
        size = item.size;
        //format = item.format;

        return true;
    }

    inline int getCount() { return m_items.count(); }

private:

    bool addItem( byte_t*& data, size_t size, bool isDirect )
    {
        Item item = { data, size, isDirect };
        m_items.add( item );

        return true;
    }

private:

    List<Item> m_items;

    friend class _PluginModel;
};
